Zero copy socket splicing

ABSTRACT

Some embodiments provide a novel method for splicing Transmission Control Protocol (TCP) sockets on a computing device that processes a kernel of an operating system. The method receives a set of packets at a first TCP socket of the kernel. The method stores the set of packets at a kernel memory location sends the set of packets directly from the kernel memory location out through a second TCP socket of the kernel.

BACKGROUND

In the field of computing, data transfers from one computer to anothertake up a significant amount of computing time. One of the processesthat make this problem worse is that in some operations, such as virtualcomputing, data may need to be accessed by multiple separate processeson a particular physical machine (e.g., a host machine of a data center,standalone computer, etc.). In the prior art, different processes mayeach need their own copy of a set of data. In such circumstances, dataused by multiple processes on the same machine will be copied, sometimesmultiple times, from one memory location (accessible by a first process)to another memory location (accessible to a second process) on the samemachine. Such copying may slow down the transmission and/or processingof the data. For example, in a prior art socket splicing operation,incoming data on a receiving socket is copied from a first memorylocation used by a receiving socket, to a second, intermediary memorylocation. The data is then copied from the intermediate memory locationto a third memory location used by a transmitting socket. Eachadditional copy operation slows down the transmission of the data.

In some of the prior art, Berkeley Sockets (a.k.a. BSD sockets) areoften used for inter process communication and are the de-facto standardAPI for I/O (convenient API for user-space I/O). With BSD, splicing TCPsockets requires performing two I/O operations (one read operation andone write operation) per I/O buffer. Additional performance costsinclude memory copying that consumes several CPU cycles and hurt otherprocesses by “polluting” shared L3 cache and putting additional pressureon the memory channels. The performance costs also include additionalsystem calls and a slow network stack. High-speed Ethernet speeds arereduced by these performance costs of the BSD Sockets because networkspeeds have outstripped those of the CPU and memory. Thus operationsthat require extra CPU and memory use become a bottleneck for datatransmission. Because the network transmits data faster than a singleCPU can feed the data into the network, more than a single CPU core isrequired to simply saturate a network link.

Attempts have been made to eliminate these performance costs by creatingnetwork systems that bypass the kernel of a computer in the networktransmission path, such as with DPDK and Netmap. The kernel bypassmethods attempt to avoid the performance penalties associated with BSDSockets. However, by bypassing the kernels, these methods lose the useof network infrastructure that already exists inside the kernel. Withoutthe existing kernel infrastructure, the kernel bypass methods require asubstitute for that network. Thus, the developers of such kernel bypassmethods also need to re-develop existing network infrastructure of thekernels (e.g., IP, TCP, ICMP, IGMP). Therefore, there is a need in theart for a dedicated memory allocator for I/O operations that inherentlyfacilitates zero-copy I/O operations and exceptionless system callsrather than merely bypassing the kernel.

BRIEF SUMMARY

Modern computers use a bifurcated structure that includes a coreoperating system (the kernel) and applications that access that kerneloperating in a user-space. Some data is used by both the kernel and byapplications in the user-space. The prior art copies the data frommemory locations used by the kernel to separate memory locations used byapplications of the user-space. Unlike that prior art, some embodimentsprovide a novel method for performing zero-copy operations using adedicated memory allocator for I/O operations (MAIO). Zero-copyoperations are operations that allow separate processes (e.g., akernel-space process and a user-space process, two sockets in akernel-space, etc.) to access the same data without copying the databetween separate memory locations. The term “kernel-space process,” asused herein, encompasses any operation or set of operations by thekernel, including operations that are part of a specific process,operations called by a specific process, or operations independent ofany specific process.

To enable the zero-copy operations that share data between user-spaceprocesses and kernel-space processes without copying the data, themethod of some embodiments provides a user-space process that maps apool of dedicated kernel memory pages to a virtual memory address spaceof user-space processes. The method allocates a virtual region of thememory for zero-copy operations. The method allows access to the virtualregion by both the user-space process and a kernel-space process. TheMAIO system of the present invention greatly outperforms standardcopying mechanism and performs at least on par and in many cases betterthan existing zero-copy techniques while preserving the ubiquitous BSDSockets API.

In some embodiments, the method only allows a single user to access aparticular virtual region. In some embodiments, the allocated virtualregion implements a dedicated receiving (RX) ring for a networkinterface controller (NIC). The dedicated RX ring may be limited to asingle tuple (e.g., a single combination of source IP address, sourceport address, destination IP address, destination port address, andprotocol). The dedicated RX ring may alternately be limited to a definedgroup of tuples.

In the method of some embodiments, the allocated virtual regionimplements a dedicated transmission (TX) ring for a NIC. Similar to thecase in which the virtual region implements an RX ring, the dedicated TXring may be limited to a single tuple or a defined group of tuples.

The kernel has access to a finite amount of memory. Allocating thatmemory for use in zero-copy operations prevents the allocated memoryfrom being used for other kernel functions. If too much memory isallocated, the kernel may run out of memory. Accordingly, in addition toallocating virtual memory, the user-space process of some embodimentsmay also de-allocate memory to free it for other kernel uses. Therefore,the user-space process of some embodiments identifies virtual memory,already allocated to zero-copy operations, to be de-allocated. In somecases, a user-space process may not de-allocate enough memory.Therefore, in some embodiments, when the amount of memory allocated bythe user-space process is more than a threshold amount, the kernel-spaceprocess de-allocates at least part of the memory allocated by theuser-space process. In some embodiments, either in addition to orinstead of the kernel-space process de-allocating memory, when theamount of memory allocated by the user-space process is more than athreshold amount, the kernel-space process prevents the user-spaceprocess from allocating more memory.

In some embodiments, the kernel-space process is a guest kernel-spaceprocess on a guest virtual machine operating on a host machine. Themethod may additionally allow access to the virtual region by auser-space process of the host machine and/or a kernel-space process ofthe host.

Zero-copy processes can also be used for TCP splicing. Some embodimentsprovide a method of splicing TCP sockets on a computing device (e.g., aphysical computer or a virtual computer) that processes a kernel of anoperating system. The method receives a set of packets at a first TCPsocket of the kernel, stores the set of packets at a kernel memorylocation, and sends the set of packets directly from the kernel memorylocation out through a second TCP socket of the kernel. In someembodiments, the receiving, storing, and sending are performed without asystem call. Some embodiments preserve standard BSD Sockets API butprovide seamless zero-copy I/O support.

Packets may sometimes come in to the receiving socket faster than thetransmitting socket can send them on, causing a memory buffer to fill.If the memory buffer becomes completely full and packets continue to bereceived, packets would have to be discarded rather than sent. Thecapacity of a socket to receive packets without its buffer beingoverwhelmed is called a “receive window size.”

In some embodiments, when the buffer is full beyond a threshold level,the method sends an indicator of a reduced size of the receive window tothe original source of the set of packets. In more severe cases, in someembodiments, when the buffer is full, the method sends an indicator tothe original source of the set of packets that the receive window sizeis zero. In general, the buffer will be filled by the receiving socketand emptied (partially or fully) by the transmitting socket. That is,memory in the buffer will become available as the transmitting socketsends data out and releases the buffer memory that held that data.Accordingly, the method of some embodiments sends multiple indicators tothe original source of the packets as the buffer fullness fluctuates.For example, when the transmitting socket empties the buffer, the methodof some embodiments sends a second indicator that the receive windowsize is no longer zero.

In some embodiments, the set of packets is a first set of packets andthe method waits for the first set of packets to be sent by the secondTCP socket before allowing a second set of packets to be received by thefirst TCP socket. In some such embodiments, the kernel memory locationidentifies a set of memory pages; the method frees the memory pages witha driver completion handler after the data stored in the memory pages issent.

The preceding Summary is intended to serve as a brief introduction tosome embodiments of the invention. It is not meant to be an introductionor overview of all inventive subject matter disclosed in this document.The Detailed Description that follows and the Drawings that are referredto in the Detailed Description will further describe the embodimentsdescribed in the Summary as well as other embodiments. Accordingly, tounderstand all the embodiments described by this document, a full reviewof the Summary, Detailed Description, the Drawings and the Claims isneeded. Moreover, the claimed subject matters are not to be limited bythe illustrative details in the Summary, Detailed Description and theDrawing.

BRIEF DESCRIPTION OF THE DRAWINGS

The novel features of the invention are set forth in the appendedclaims. However, for purpose of explanation, several embodiments of theinvention are set forth in the following figures.

FIG. 1 conceptually illustrates a process that allocates memory as ashared memory pool for user-space and kernel-space processes.

FIG. 2 conceptually illustrates a process for allocating a virtualregion of memory for zero-copy operations.

FIG. 3 conceptually illustrates kernel memory allocated as a virtualmemory address space in a user-space.

FIG. 4 conceptually illustrates system calls using dedicated ringbuffers.

FIG. 5 illustrates a zero-copy memory accessible by the user-spaces andkernel-spaces of both a guest machine and a host machine.

FIG. 6 illustrates a dedicated memory allocation I/O system operating ona multi-tenant host.

FIG. 7 conceptually illustrates a process 700 of some embodiments forallocating and de-allocating kernel memory for shared memory access withkernel-space and user-space processes.

FIG. 8 conceptually illustrates a process 800 for zero-copy TCPsplicing.

FIG. 9 conceptually illustrates zero-copy TCP splicing between twokernel sockets.

FIG. 10 conceptually illustrates an electronic system with which someembodiments of the invention are implemented.

DETAILED DESCRIPTION

In the following detailed description of the invention, numerousdetails, examples, and embodiments of the invention are set forth anddescribed. However, it will be clear and apparent to one skilled in theart that the invention is not limited to the embodiments set forth andthat the invention may be practiced without some of the specific detailsand examples discussed.

Modern computers use a bifurcated structure that includes a coreoperating system (the kernel) and applications that access that kerneloperating in a user-space. Some data is used by both the kernel and byapplications in the user-space. The prior art copies the data frommemory locations used by the kernel to separate memory locations used byapplications of the user-space. Unlike that prior art, some embodimentsprovide a novel method for performing zero-copy operations using adedicated memory allocator for I/O operations (MAIO). Zero-copyoperations are operations that allow separate processes (e.g., akernel-space process and a user-space process, two sockets in akernel-space, etc.) to access the same data without copying the databetween separate memory locations. The term “kernel-space process,” asused herein, encompasses any operation or set of operations by thekernel, whether these operations are part of a specific process orindependent of any specific process.

Some embodiments provide a novel method for performing zero-copyoperations using dedicated memory allocated for I/O operations. FIG. 1conceptually illustrates a process 100 that allocates memory as a sharedmemory pool for user-space and kernel-space processes. FIG. 2conceptually illustrates a process 200 for allocating a virtual regionof memory for zero-copy operations. The process 100 of FIG. 1 andprocess 200 of FIG. 2 will be described by reference to FIG. 3. FIG. 3conceptually illustrates kernel memory allocated as a virtual memoryaddress space in a user-space. FIG. 3 includes a kernel-space 310 withkernel memory 320 and user-space 330 with virtual memory 340. Kernelmemory 320 includes allocated memory pages 325 which in turn includememory 327 allocated for zero-copy operations. A user-space process 350runs in user-space 330 and a kernel-space process 360 runs inkernel-space 310.

The process 100 of FIG. 1 prepares memory for sharing data betweenuser-space processes and kernel-space processes without copying thedata. The method 100 allocates (at 105) a set of memory locations as ashared memory pool. In some embodiments, the memory pool is allocatedfrom kernel memory. An example of this is shown in FIG. 3, with memorypages 325 allocated as shared memory pages. The process 100 (of FIG. 1)then maps (at 110) a pool of the dedicated kernel memory to a virtualmemory address space of user-space processes. FIG. 3 illustrates such amapping with the allocated memory pages 325 mapped to virtual memory320. Although the embodiment of FIG. 3 shows the allocated memory pages325 mapped to a single virtual memory space, in some embodiments theallocated memory may be mapped to multiple virtual memory address spaces(e.g., for multiple processes in a single user-space, processes inmultiple user-spaces, processes owned by multiple tenants of adatacenter, etc.)

After the memory is mapped, the process 100 then provides (at 115) thememory location identifier to a kernel-space process to allow thekernel-space process to access the virtual memory region. The process100 also provides (at 120) a memory location identifier to a user-spaceprocess to access the virtual-memory region.

Although the process 100 is shown as providing memory locationidentifier to the kernel-space process first, one of ordinary skill inthe art will understand that other embodiments provide the memorylocation identifier to the kernel-space process after providing it tothe user-space process. Additionally, in some embodiments, the featuresof either operation 115 or operation 120 may be combined with thefeatures of operation 110 into a single operation in which the mappingoperation is performed by a kernel-space operation or a user-spaceoperation which creates the memory location identifier of operations 115or 120 in the course of a mapping operation similar to operation 110. Insome embodiments, the location identifier may supply an identifier of amemory location in kernel-space at which the memory begins and/or acorresponding memory location in a virtual memory for the user-space atwhich the memory begins. In embodiments in which the kernel-space andthe user-space each uses a separate addressing locations for the samephysical memory location, this or whatever other location identifier oridentifiers are exchanged between the user-space process and the kernelallows the kernel to identify an address of a page, in the kernel-spacememory, based on a supplied memory page address, in the virtual memory,provided to the kernel by the user-space process. Similarly, in someembodiments, the user-space process may translate the address locationsbetween the virtual memory addresses and the kernel-space memoryaddresses.

Once the process 100 maps a pool of dedicated kernel memory pages to avirtual memory address space of user-space processes, some embodimentsprovide a process for allocating a virtual region of that dedicatedkernel memory for zero-copy operations. FIG. 2 conceptually illustratesa process 200 for allocating a virtual region of memory for zero-copyoperations. The process 200 receives (at 205) a memory locationidentifier of an allocated pool of memory shared by kernel-processes anduser-space processes. In some embodiments, the memory locationidentifier is received from a user-space process or kernel-space processthat allocates the memory (e.g., in operation 110 of FIG. 1).

The process 200 allocates (at 210) a virtual region of memory from theidentified memory location for use in a zero-copy memory operation. Theprocess 200 provides (at 215) an identifier of the allocated memory forzero-copy memory operations to a kernel-space process and a user-spaceprocess. In FIG. 3, the zero-copy memory is accessible by bothuser-space process 350 and kernel-space process 360. Although process200 is described as being performed by a user-space process, one ofordinary skill in the art will understand that in some embodiments akernel-space process allocates the memory for zero-copy memoryoperations instead of the user-space process allocating the memory.Similarly, in some embodiments, both user-space processes andkernel-space processes can allocate memory for zero-copy memoryoperations.

Zero-copy operations between kernel-space and user-space are useful inmultiple processes. One such process is receiving and transmitting datain I/O operations. In existing systems, the direct and indirect costs ofsystem calls impact user-space I/O performance. Some embodiments of thepresent invention avoid these costs by offloading the I/O operation toone or more dedicated kernel threads which will perform the I/Ooperation using kernel sockets rather than requiring user-spaceprocesses to perform the I/O operations. In some embodiments, adedicated ring memory buffer (sometimes called an RX ring) is used forreceiving data at a network interface controller (NIC) and a seconddedicated ring memory buffer is used for transmitting data from the NIC.The dedicated RX ring may be limited to a single tuple (e.g., a singlecombination of source IP address, source port address, destination IPaddress, destination port address, and protocol). The dedicated RX ringmay alternately be limited to a defined group of tuples. Similarly, insome embodiments an allocated virtual region implements a dedicatedtransmission ring memory buffer (sometimes called a TX ring) for a NIC.As in the case in which the virtual region implements an RX ring, thededicated TX ring may be limited to a single tuple or a defined group oftuples.

An example of such dedicated RX and TX rings is shown in FIG. 4. FIG. 4conceptually illustrates send and receive threads using dedicated ringbuffers. FIG. 4 includes device drivers 400 and a network stack 410operating in kernel-space, dedicated transmission ring memory buffers415 which receive data 420 from kernel system calls (i.e., system callssending messages from the kernel to the user-space), dedicated receivingring memory buffers 425 which transmit data 430, through kernel systemcalls (i.e., system calls receiving messages at the kernel from theuser-space).

Although the dedicated transmission memory buffer ring 415 is shown astwo separate items, one in the kernel-space and one straddling a dashedline separating user-space from kernel-space, they are the same memorybuffer ring shown from two different perspectives, not two separateentities. Kernel processes and user processes each have access to thetransmission memory buffer ring 415 and the data 420 sent from thekernel with system calls 417 in the user-space is all data stored in thetransmission memory buffer ring 415. In addition to storing data 420 forMAIO pages, in some embodiments, the dedicated transmission ring may beused to store data 422 for a kernel buffer without needing any specialcare for data separation.

As with dedicated memory buffer ring 415, although the dedicatedreceiving memory buffer ring 425 is shown as two separate items, one inthe kernel-space and one straddling a dashed line separating user-spacefrom kernel-space, they are also a single memory buffer ring shown fromtwo different perspectives, not two separate entities. Kernel processesand user processes each have access to the transmission memory bufferring 425 and the data 430 received by the kernel with system calls 427from the user-space is all data stored in the transmission memory bufferring 425.

Some embodiments use dedicated threads with the ring buffers. This hasmultiple advantages. For example, it reduces the need for some systemcalls which would otherwise slow down the data transmission. Forexample, when sending data some embodiments do not require a send_msgsystem call, but instead use an I/O descriptor (e.g., struct, msghdr,and int flags) written to a shared memory ring buffer. Additionally,splitting (between the kernel-space process and the user-space process)responsibility for performing I/O preserves the existing socket API,facilitates exceptionless system calls, and allows for better parallelprogramming. Furthermore, bifurcated I/O (splitting the responsibilityfor performing the I/O) enables the separation of the applicationcomputations and the TCP computations to different CPU cores. In someembodiments, dedicated kernel threads are also used to perform memoryoperations (e.g., retrieving memory buffers back from the user).

Although the embodiment of FIG. 4 shows receiving and transmitting onlythrough zero-copy operations, in other embodiments, both zero-copy andstandard send and receive operations are supported. For example, someembodiments provide support for standard I/O operations for apps withsmall I/O needs (e.g., where the copying of only a small amount of datareduces or eliminates the savings from zero-copy operations). Instandard mode, the sent buffer is copied to a new MAIO buffer beforebeing sent. In some embodiments the common memory is allocated using aNIC driver. In some embodiments, the NIC driver dedicates the memoryusing an application device queue (ADQ). Various embodiments may map thekernel-space memory to the virtual (user-space) memory after the NICdriver dedicates the memory for user space, after the NIC driverdedicates the memory to kernel-space, or in some embodiments the NICdriver may perform the mapping of the kernel-space memory to the virtualmemory as well as dedicating the memory to a user-space process using anADQ.

The previous figure illustrated the use of the present invention in acomputer system with a single user-space and a single kernel-space.However, the invention is not limited to such systems. In someembodiments, the invention operates on a guest machine (e.g., a virtualmachine operating on a physical host machine). In some such embodiments,both the host system and the guest system are designed to use zero-copyoperations and are both able to access the shared memory. FIG. 5illustrates a zero-copy memory accessible by the user-spaces andkernel-spaces of both a guest machine and a host machine. FIG. 5includes a host kernel-space 500, a host user-space 502, a guestkernel-space 504, and a guest user-space 506. A kernel-space process 530operates in the guest-kernel-space 504 and receives data from auser-space process 520 through a dedicated memory ring buffer 510.Similarly, another kernel-space process 550 operates in theguest-kernel-space 504 and receives data from a user-space process 560through a dedicated memory ring buffer 540.

The embodiments of FIG. 5 includes only a single guest machine,eliminating security issues that might arise from exposing data from oneguest machine, that is owned by a first tenant, to a second data machinethat is owned by a second tenant. However, even when multiple tenantshave guest machines on the same host machine, the present inventionstill provides security for the tenants' data.

In order to protect data when user-processes now seemingly have accessto sensitive kernel memory, the present invention provides entirelyseparate allocated memory to different tenants. That is, in someembodiments, the method limits access to the virtual region allocatedfor zero-copy operations to a single user. Thus, the kernel memory aparticular user has access to contains only data that the particularuser would normally have access to. FIG. 6 illustrates a dedicatedmemory allocation I/O system operating on a multi-tenant host. FIG. 6includes a host kernel-space 600 and a host user-space 602. Tenant 1 hasa guest machine with a guest kernel-space 604, and a guest user-space606. A kernel-space process 620 operates in the guest-kernel-space 604and receives data from a user-space process 630 through a dedicatedmemory ring buffer 610. Tenant 2 has a guest machine with a guestkernel-space 644, and a guest user-space 646. A kernel-space process 650operates in the guest-kernel-space 644 and receives data from auser-space process 660 through a dedicated memory ring buffer 640.Memory ring 610 is used exclusively for tenant 1, while memory ring 640is used exclusively for tenant 2. Accordingly, no data can leak fromtenant 1 to tenant 2 or vice versa through the dedicated memory ringbuffers.

Some embodiments provide additional security features. For example, insome embodiments, shared pages are only ever used by the kernel to holdI/O data buffers and not any metadata or any other data needed by thekernel. That is, the user-space process can only ever see theinformation that a user-space process has written or data bound touser-space which would be received by the user in a standard operation,even if a zero-copy operation were not used. In some embodiments, inaddition to the message data, the kernel-process is privy to transportheaders as well. In some embodiments, where the NIC supports Header/Datasplitting, the kernel-process places the headers onto non-shared buffersfor additional security. In contrast, in embodiments where all potentialreceiving memory ring buffers are shared, the MAIO would potentiallyexpose all traffic to a single observer. In the absence of driversupport for keeping different tenant data separate, the usefulness ofMAIO in such embodiments should be limited to those cases when any userwith access is trusted (e.g., sudo).

Kernel memory allocated to zero-copy operations is not available forother kernel functions. If allocated memory is not released back to thekernel while new memory continues to be allocated, the kernel may runout of memory for those other functions. Therefore, in addition toallocating virtual memory, the user-space process of some embodimentsmay de-allocate memory. That is, the user-space process may identifyvirtual memory, previously allocated to zero-copy operations, to bede-allocated.

Under some circumstances, a user-process may not properly de-allocatememory. Accordingly, in some embodiments, when the amount of memoryallocated by the user-space process is more than a threshold amount, thekernel-space process takes corrective action. In some embodiments, whenthe amount of memory allocated by the user-space process is more than athreshold amount, the kernel-space process prevents the user-spaceprocess from allocating more memory. FIG. 7 conceptually illustrates aprocess 700 of some embodiments for allocating and de-allocating kernelmemory for shared memory access with kernel-space and user-spaceprocesses. The process 700 receives (at 705) a request from a user-spaceprocess for a pool of dedicated kernel memory to be accessed by bothkernel-space and user-space processes. The process 700 determines (at710) whether the user-space process has more than a threshold amount ofkernel memory dedicated to that user-space process. In some embodiments,the threshold is a fixed amount, in other embodiments; the threshold isvariable based on available (free) system resources, relative priorityof various user-processes etc. In some embodiments, the threshold isdetermined on a per-process basis; in other embodiments, the thresholdmay be determined on a per guest machine basis or a per-tenant basis.

When the process 700 determines (at 710) that the user-process has morethan the threshold amount of memory, the process 700 uses (at 715) astandard memory allocation (e.g., the driver of the NIC uses a standardmemory allocation) and refuses to designate a pool of kernel memory forthe user-space process. For example, this occurs when a user-spaceprocess hoards MAIO buffers without releasing them to the kernel, thusstarving the kernel of needed memory. In some embodiments, when thedriver of the NIC reverts to standard memory allocation, this rendersthe user-space process unable to receive, while other process and kernelfunctionality will remain intact. After operation 715, the process 700moves on to operation 725.

When the process 700 determines (at 710) that the user-process does nothave more than the threshold amount of memory, the process 700designates (at 720) a pool of dedicated kernel memory for the user-spaceprocess to share with kernel-space processes. After operation 720, theprocess 700 moves on to operation 725.

The process 700 determines (at 725) whether it has received (e.g., fromthe user-space process) a request to de-allocate a pool of dedicatedkernel memory. When the process 700 has received a request tode-allocate a pool of dedicated kernel memory, the process 700de-allocates (at 730) that pool of kernel memory, freeing that pool tobe allocated for shared use with other user-space processes or for usein other kernel operations. The process then returns to operation 705when it receives a new request for a pool of memory. When the process700 determines (at 725) that it has not received a request tode-allocate a pool of dedicated kernel memory, the process 700 returnsto operation 705.

The process 700 may be used to prevent memory hoarding by a user processin circumstances when zero-copy solutions with a shared static bufferare considered dangerous because these shared pages can be exhausted andcannot be swapped out. However, some modern systems have hundreds of GBof RAM and such systems may not be exhausted during typical operation.In such systems, the user-space process might not reach a thresholdlevel requiring the kernel to refuse further memory allocation. In otherembodiments, the kernel-space process itself de-allocates memoryallocated to the user-space process rather than merely denying newallocations.

Although the previous description involved zero-copy operations usedbetween kernel-space processes and user-space processes, zero-copyprocesses can also be used in kernel-space to kernel-space operations.One example, of such kernel/kernel operations is TCP splicing. TCPsplicing is a method of splicing two socket connections inside a kernel,so that the data relayed between the two connections can be run at nearrouter speeds.

In older prior art, TCP splicing involved user-space processes as wellas kernel-space processes. In more recent prior art, a process called an“eBPF callback” is called when a packet is received. The eBPF callbackforwards the received packet to a predefined socket. However, the priorart eBPF callback is problematic due to the fact that the callback isinvoked in a non-process context. That is, the eBPF callback process hasno way to determine whether the predefined socket to which the callbackis forwarding the packet is ready to handle a packet. Therefore, whenthe destination socket cannot send (e.g., due to a closed send orreceive window); there is no feedback process that can tell the originalsender to wait for the window to open. Without this option, the notionof “back-pressure” (narrowing a receive window to tell the system thatis the original source of the packets to slow or stop transmission untilthe transmitting socket can send the packets that already arrived) isinfeasible. Back-pressure is paramount for socket splicing where the twoconnected lines are of different widths.

In contrast to the prior art eBPF callback, the present invention allowsbackpressure in the form of feedback to the original source when thetransmitting socket is not ready to receive more packets. Someembodiments provide a method of splicing TCP sockets on a computingdevice (e.g., a physical computer or a virtual computer) that processesa kernel of an operating system. The method receives a set of packets ata first TCP socket of the kernel, stores the set of packets at a kernelmemory location, and sends the set of packets directly from the kernelmemory location out through a second TCP socket of the kernel. Themethod provides back-pressure that prevents the original source of thepackets from sending packets to the receiving socket faster than thetransmitting socket of the splice can send them onward. In someembodiments, the receiving, storing, and sending are performed without asystem call.

FIG. 8 conceptually illustrates a process 800 for zero-copy TCPsplicing. The process 800 will be described by reference to FIG. 9 whichconceptually illustrates zero-copy TCP splicing between two kernelsockets. FIG. 9 includes receiving socket 910 which receives datapackets 915 and stores them in memory buffer 920 and transmitting socket930 which transmits the data packets from the memory buffer 920 withoutany intermediate copying of the data.

The process 800 of FIG. 8 receives (at 805), at a first TCP socket(e.g., such as receiving socket 910 of FIG. 9) of a kernel, a set ofdata packets (e.g., such as data packets 915 of FIG. 9). The process 800of FIG. 8 stores (at 810) the data packets in a kernel memory location.For example, memory buffer 920 of FIG. 9. The process 800 of FIG. 8sends (at 815) the set of packets directly from the kernel memorylocation out through a second TCP socket of the kernel. For example,transmitting socket 930 of FIG. 9. In some embodiments, the kernelmemory location identifies a set of memory pages of a particular set ofdata, and the method frees the memory pages with a driver completionhandler after the data stored in the memory pages is sent (at 815).

In some cases, the transmitting socket 930 may not be able to transmitpackets as quickly as the receiving socket 910 is able to receive them.When that occurs, the receiving socket 910 adds packets to the memorybuffer 920 faster than the transmitting socket 930 can clear the packetsby sending them. Thus, the memory buffer 920 fills up. Accordingly, theprocess 800 determines (at 820) whether the buffer fullness has crosseda threshold level. This can happen in one of two ways, by the fullnessincreasing past a first threshold or decreasing past a second threshold.One of ordinary skill in the art will understand that in someembodiments the first and second thresholds will be the same and inother embodiments the thresholds will be different.

When the buffer becomes full beyond a first threshold level, the process800 sends (at 825) an indicator from the first TCP socket (e.g.,receiving socket 910 of FIG. 9) to a source of the set of packets (notshown). The indicator communicates that the size of a receive window ofthe first TCP socket has been adjusted downward. After the window sizeis reduced the process 800 returns to operation 805 and loops throughoperations 805-820 until the buffer fullness passes another threshold at820. When the original source of the packets receives such an indicator,it slows down transmission of new packets to the receiving socket 910.If this adjustment reduces the rate of receiving incoming packets belowthe rate that the transmitting socket, then the buffer will graduallyempty while the process 800 loops through operations 805-820.

The reduction of the rate of incoming packets will eventually result inthe buffer dropping below a threshold (on subsequent passes through theloop). At that point, the process 800 then sends (at 825) an indicatorincreasing the size of the receiving window. Once the indicator is sent,the process 800 returns to operation 805 and continues to loop throughoperations 805-820, occasionally returning to operation 825 to adjustthe size of the receive window up or down as needed before returning tothe loop again.

While the adjustments are intended to keep the packets arriving at arate that always leaves adequate space in the buffer, in some cases, thebuffer may become nearly or entirely full. In such cases, the process800 sends (at 825) an indicator to the original source of the set ofpackets, that the receive window size is zero, stopping the transmissionof packets to the receiving socket entirely until the transmittingsocket clears enough space in the buffer. Subsequent passes through theloop send (at 815) packets, but do not receive or store new ones untilthe buffer has enough space to resume receiving and the process 800sends (at 825) an indicator that the receive window is open again.

Although the above described figures disclose the elements of someembodiments, some embodiments may include other elements. For example,in some embodiments, the memory allocator uses a pool of dedicatedcompound memory pages (i.e., _GFP_COMP). In some embodiments, theallocator is partly based on two mechanisms: a page frag mechanism over64 KB buffers and these buffers in turn are allotted by a magazineallocator. This allocation scheme efficiently allocates variable sizebuffers in the kernel. Variable size allocation is useful to supportvariable sizes of MTU & HW offloads (e.g., HW GRO). To facilitatezero-copy, these pages are mapped once to the virtual memory addressspace of the privileged user-space process. The user-space processaccesses MAIO buffers in two ways in some embodiments: (1) Zero-copysend, in which the user-space process has to mmap (mmap is a Unix systemcall that maps files or devices into memory), or perform a similaroperation appropriate to the operating system on which the invention isimplemented, the MAIO buffer and then allocate a virtual region for itsown use (the allocated region's size is a multiple of 64 KB in someembodiments); and (2) Zero-copy receive, in which the user-space processperforms a zero-copy receive operation to get MAIO buffers. Theuser-space process of some embodiments can return memory to the kernelvia an exception-less mechanism.

With respect to Zero-copy support for kernel sockets, some embodimentsexpand the existing Linux TCP API with a tcp_read_sock_zcopy for RX andadd a new msg flag, SOCK_KERN_ZEROCOPY, for tcp_sendmsg_locked in TX.With respect to receiving, some embodiments provide a new function,tcp_read_sock_zcopy, based on existing infrastructure i.e.,tcp_read_sock. It is used by tcp_splice_read to collect buffers from asocket without copying. When kernel memory is used for I/O (e.g., forTCP socket splicing), enabling zero-copy is less complicated whencompared to zero-copy from user-space. The pages are already pinned inmemory and there is no need for a notification on TX completion. Thepages are reference counted, and can be freed by the device drivercompletion handler (do_tcp_sendpages). Instead of modifying the behaviorof tcp_sendmsg_locked, it is also possible to use do_tcp_sendpages,which is used in splicing. Ironically, do_tcp_sendpages accepts only onepage fragment (i.e., struct page, size and offset) per invocation anddoes not work with a scatter-gather list, which tcp_sendmsg_lockedsupports. Although the above description refers to TCP, one of ordinaryskill in the art will understand that the inventions described hereinalso apply to other standards such as UDP, etc.

FIG. 10 conceptually illustrates an electronic system 1000 with whichsome embodiments of the invention are implemented. The electronic system1000 can be used to execute any of the control, virtualization, oroperating system applications described above. The electronic system1000 may be a computer (e.g., a desktop computer, personal computer,tablet computer, server computer, mainframe, a blade computer etc.),phone, PDA, or any other sort of electronic device. Such an electronicsystem includes various types of computer readable media and interfacesfor various other types of computer readable media. Electronic system1000 includes a bus 1005, processing unit(s) 1010, a system memory 1025,a read-only memory 1030, a permanent storage device 1035, input devices1040, and output devices 1045.

The bus 1005 collectively represents all system, peripheral, and chipsetbuses that communicatively connect the numerous internal devices of theelectronic system 1000. For instance, the bus 1005 communicativelyconnects the processing unit(s) 1010 with the read-only memory 1030, thesystem memory 1025, and the permanent storage device 1035.

From these various memory units, the processing unit(s) 1010 retrieveinstructions to execute and data to process in order to execute theprocesses of the invention. The processing unit(s) may be a singleprocessor or a multi-core processor in different embodiments.

The read-only-memory (ROM) 1030 stores static data and instructions thatare needed by the processing unit(s) 1010 and other modules of theelectronic system. The permanent storage device 1035, on the other hand,is a read-and-write memory device. This device is a non-volatile memoryunit that stores instructions and data even when the electronic system1000 is off. Some embodiments of the invention use a mass-storage device(such as a magnetic or optical disk and its corresponding disk drive) asthe permanent storage device 1035.

Other embodiments use a removable storage device (such as a floppy disk,flash drive, etc.) as the permanent storage device. Like the permanentstorage device 1035, the system memory 1025 is a read-and-write memorydevice. However, unlike storage device 1035, the system memory is avolatile read-and-write memory, such a random access memory. The systemmemory 1025 stores some of the instructions and data that the processorneeds at runtime. In some embodiments, the invention's processes arestored in the system memory 1025, the permanent storage device 1035,and/or the read-only memory 1030. From these various memory units, theprocessing unit(s) 1010 retrieve instructions to execute and data toprocess in order to execute the processes of some embodiments.

The bus 1005 also connects to the input and output devices 1040 and1045. The input devices 1040 enable the user to communicate informationand select commands to the electronic system. The input devices 1040include alphanumeric keyboards and pointing devices (also called “cursorcontrol devices”). The output devices 1045 display images generated bythe electronic system 1000. The output devices 1045 include printers anddisplay devices, such as cathode ray tubes (CRT) or liquid crystaldisplays (LCD). Some embodiments include devices such as a touchscreenthat function as both input and output devices.

Finally, as shown in FIG. 10, bus 1005 also couples electronic system1000 to a network 1065 through a network adapter (not shown). In thismanner, the computer can be a part of a network of computers (such as alocal area network (“LAN”), a wide area network (“WAN”), or an Intranet,or a network of networks, such as the Internet. Any or all components ofelectronic system 1000 may be used in conjunction with the invention.

Some embodiments include electronic components, such as microprocessors,storage and memory that store computer program instructions in amachine-readable or computer-readable medium (alternatively referred toas computer-readable storage media, machine-readable media, ormachine-readable storage media). Some examples of such computer-readablemedia include RAM, ROM, read-only compact discs (CD-ROM), recordablecompact discs (CD-R), rewritable compact discs (CD-RW), read-onlydigital versatile discs (e.g., DVD-ROM, dual-layer DVD-ROM), a varietyof recordable/rewritable DVDs (e.g., DVD-RAM, DVD-RW, DVD+RW, etc.),flash memory (e.g., SD cards, mini-SD cards, micro-SD cards, etc.),magnetic and/or solid state hard drives, read-only and recordableBlu-Ray® discs, ultra-density optical discs, any other optical ormagnetic media, and floppy disks. The computer-readable media may storea computer program that is executable by at least one processing unitand includes sets of instructions for performing various operations.Examples of computer programs or computer code include machine code,such as is produced by a compiler, and files including higher-level codethat are executed by a computer, an electronic component, or amicroprocessor using an interpreter.

While the above discussion primarily refers to microprocessor ormulti-core processors that execute software, some embodiments areperformed by one or more integrated circuits, such asapplication-specific integrated circuits (ASICs) or field-programmablegate arrays (FPGAs). In some embodiments, such integrated circuitsexecute instructions that are stored on the circuit itself.

As used in this specification, the terms “computer”, “server”,“processor”, and “memory” all refer to electronic or other technologicaldevices. These terms exclude people or groups of people. For thepurposes of the specification, the terms display or displaying meansdisplaying on an electronic device. As used in this specification, theterms “computer readable medium,” “computer readable media,” and“machine readable medium” are entirely restricted to tangible, physicalobjects that store information in a form that is readable by a computer.These terms exclude any wireless signals, wired download signals, andany other ephemeral signals.

This specification refers throughout to computational and networkenvironments that include virtual machines (VMs). However, virtualmachines are merely one example of data compute nodes (DCNs) or datacompute end nodes, also referred to as addressable nodes. DCNs mayinclude non-virtualized physical hosts, virtual machines, containersthat run on top of a host operating system without the need for ahypervisor or separate operating system, and hypervisor kernel networkinterface modules.

VMs, in some embodiments, operate with their own guest operating systemson a host using resources of the host virtualized by virtualizationsoftware (e.g., a hypervisor, virtual machine monitor, etc.). The tenant(i.e., the owner of the VM) can choose which applications to operate ontop of the guest operating system. Some containers, on the other hand,are constructs that run on top of a host operating system without theneed for a hypervisor or separate guest operating system. In someembodiments, the host operating system uses name spaces to isolate thecontainers from each other and therefore provides operating-system levelsegregation of the different groups of applications that operate withindifferent containers. This segregation is akin to the VM segregationthat is offered in hypervisor-virtualized environments that virtualizesystem hardware, and thus can be viewed as a form of virtualization thatisolates different groups of applications that operate in differentcontainers. Such containers are more lightweight than VMs.

Hypervisor kernel network interface modules, in some embodiments, arenon-VM DCNs that include a network stack with a hypervisor kernelnetwork interface and receive/transmit threads. One example of ahypervisor kernel network interface module is the vmknic module that ispart of the ESXi™ hypervisor of VMware, Inc.

It should be understood that while the specification refers to VMs, theexamples given could be any type of DCNs, including physical hosts, VMs,non-VM containers, and hypervisor kernel network interface modules. Infact, the example networks could include combinations of different typesof DCNs in some embodiments.

While the invention has been described with reference to numerousspecific details, one of ordinary skill in the art will recognize thatthe invention can be embodied in other specific forms without departingfrom the spirit of the invention. In addition, a number of the figuresconceptually illustrate processes. The specific operations of theseprocesses may not be performed in the exact order shown and described.The specific operations may not be performed in one continuous series ofoperations, and different specific operations may be performed indifferent embodiments. Furthermore, the process could be implementedusing several sub-processes, or as part of a larger macro process. Thus,one of ordinary skill in the art would understand that the invention isnot to be limited by the foregoing illustrative details, but rather isto be defined by the appended claims.

We claim:
 1. A method of splicing Transmission Control Protocol (TCP)sockets on a computing device that processes a kernel of an operatingsystem, the method comprising: receiving a set of packets at a first TCPsocket of the kernel; storing the set of packets at a kernel memorylocation; and sending the set of packets directly from the kernel memorylocation out through a second TCP socket of the kernel.
 2. The method ofclaim 1 further comprising sending an indicator of a receive window sizeof the first TCP socket to a source of the set of packets.
 3. The methodof claim 2, wherein the kernel memory location comprises a location of abuffer of a particular size.
 4. The method of claim 3 furthercomprising, when the buffer is full beyond a threshold level, sending anindicator of a reduced size of the receive window to the original sourceof the set of packets.
 5. The method of claim 3 further comprising, whenthe buffer is full, sending an indicator that the receive window size iszero to the original source of the set of packets.
 6. The method ofclaim 5, wherein the indicator is a first indicator, the method furthercomprising: emptying the buffer by sending packets from the second TCPsocket; and sending a second indicator that the receive window size isno longer zero.
 7. The method of claim 1 wherein the set of packets is afirst set of packets, the method further comprising waiting for thefirst set of packets to be sent by the second TCP socket before allowinga second set of packets to be received by the first TCP socket.
 8. Themethod of claim 7, wherein the kernel memory location comprises a set ofmemory pages, the method further comprising freeing the memory pageswith a driver completion handler after the pages are sent.
 9. The methodof claim 1, wherein: the first TCP socket writes data comprising the setof packets to the kernel memory location upon first receiving the set ofpackets, and the second TCP socket reads the data from the same kernelmemory location.
 10. The method of claim 1, wherein the receiving,storing, and sending are performed without a system call.
 11. Anon-transitory machine readable medium storing a program which whenexecuted by at least one processing unit splices sockets on a computingdevice that processes a kernel of an operating system, the programcomprising sets of instructions for: receiving a set of packets at afirst socket of the kernel; storing the set of packets at a kernelmemory location; and sending the set of packets directly from the kernelmemory location out through a second socket of the kernel.
 12. Thenon-transitory machine readable medium of claim 11, wherein the programfurther comprises sets of instructions for sending an indicator of areceive window size of the first socket to a source of the set ofpackets.
 13. The non-transitory machine readable medium of claim 12,wherein the kernel memory location comprises a location of a buffer of aparticular size.
 14. The non-transitory machine readable medium of claim13 wherein the program further comprises sets of instructions for, whenthe buffer is full beyond a threshold level, sending an indicator of areduced size of the receive window to the original source of the set ofpackets.
 15. The non-transitory machine readable medium of claim 13wherein the program further comprises sets of instructions for, when thebuffer is full, sending an indicator that the receive window size iszero to the original source of the set of packets.
 16. Thenon-transitory machine readable medium of claim 15, wherein theindicator is a first indicator, the method further comprising: emptyingthe buffer by sending packets from the second socket; and sending asecond indicator that the receive window size is no longer zero.
 17. Thenon-transitory machine readable medium of claim 11 wherein the set ofpackets is a first set of packets, the method further comprising waitingfor the first set of packets to be sent by the second socket beforeallowing a second set of packets to be received by the first socket. 18.The non-transitory machine readable medium of claim 17, wherein thekernel memory location comprises a set of memory pages, the methodfurther comprising freeing the memory pages with a driver completionhandler after the pages are sent.
 19. The non-transitory machinereadable medium of claim 11, wherein: the first socket writes datacomprising the set of packets to the kernel memory location upon firstreceiving the set of packets, and the second socket reads the data fromthe same kernel memory location.
 20. The non-transitory machine readablemedium of claim 11, wherein the receiving, storing, and sending areperformed without a system call.